package com.nian.mongodb.service.service.impl;

import com.nian.mongodb.service.dao.DepartmentRepository;
import com.nian.mongodb.service.model.Department;
import com.nian.mongodb.service.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 用途：
 * 开发：zhangmj
 * 日期：2020/4/12 0012 18:58
 */
@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentRepository departmentRepository;

    @Override
    public Department findByCode(String code) {
        if(StringUtils.isEmpty(code)){
            return null;
        }
        return departmentRepository.findByCode(code);
    }

    @Override
    public List<Department> findByName(String name) {
        if(StringUtils.isEmpty(name)){
            return null;
        }
        return departmentRepository.findByName(name);
    }

    @Override
    public Department save(Department model) {
        if(model == null){
            return model;
        }
        return departmentRepository.save(model);
    }

    @Override
    public void saveAll(List<Department> list) {
        if(!CollectionUtils.isEmpty(list)){
            departmentRepository.saveAll(list);
        }
    }
}
